package com.adrian.misc.fractal.math;

public class ComplexNumber {
	public double X = 0.0;
	public double Y = 0.0;

	public ComplexNumber(double x, double y) {
		X = x;
		Y = y;
	}
	
	public ComplexNumber(ComplexNumber z) {
		X = z.X;
		Y = z.Y;
	}
	
	public ComplexNumber() {
		this (0,0);
	}

	public void set(ComplexNumber z) {
		X = z.X;
		Y = z.Y;
	}

	public double abs() {
		return (Math.sqrt(X * X + Y * Y));
	}

	public void sqr() {
		double Xnew  = X * X - Y * Y;
		Y = 2 * X * Y;
		X = Xnew;
	}

	public ComplexNumber add(ComplexNumber Z) {
		X += Z.X;
		Y += Z.Y;
		return this;
	}

	public void add(double x) {
		X += x;
	}
	@Override
	public String toString() {
		return (""+ X + "+i" +Y);
	}
}
